package com.weavernorth.action.jb.utils;

import weaver.general.BaseBean;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @Author: bruseewang
 * @Package: com.weavernorth.action.jb.utils
 * @date: 2020/5/14 17:54
 * @description: 取某年某月最后一天的日期
 */
public class LastDayOfMonth {
    public static String LastDayOfMonth(int year,int month)
    {
        Calendar calendar = Calendar.getInstance();
        //设置年
        calendar.set(Calendar.YEAR,year);
        //设置月
        calendar.set(Calendar.MONTH,month-1);
        //获取某月最大天数
        BaseBean bb=new BaseBean();
        bb.writeLog("获取某月最大天数");
        int lastDay=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        bb.writeLog("某月最大天数为。。"+lastDay);
        //设置日历中月份的最大天数
        bb.writeLog("设置日历中月份的最大天数。。");
        calendar.set(Calendar.DAY_OF_MONTH,lastDay);
        //格式化日期
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String lastDayOfMonth  = sdf.format(calendar.getTime());
        bb.writeLog("格式化日期。。"+lastDayOfMonth+"");
        return lastDayOfMonth;
    }
}
